﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Infinity.Expressions
{
	public partial class BlockBuilder : ICollection<ParameterExpression>
	{
		public void Add(ParameterExpression item)
		{
			var listVariables = BlockExpression.Variables.ToList();
			listVariables.Add(item);
			BlockExpression = Expression.Block(listVariables, BlockExpression.Expressions);
		}

		public bool Contains(ParameterExpression item)
		{
			return BlockExpression.Variables.Contains(item);
		}

		public void CopyTo(ParameterExpression[] array, int arrayIndex)
		{
			throw new NotImplementedException();
		}

		public bool Remove(ParameterExpression item)
		{
			var listVariables = BlockExpression.Variables.ToList();
			bool succeed = listVariables.Remove(item);

			BlockExpression = Expression.Block(listVariables, BlockExpression.Expressions);

			return succeed;
		}

		IEnumerator<ParameterExpression> IEnumerable<ParameterExpression>.GetEnumerator()
		{
			return BlockExpression.Variables.GetEnumerator();
		}
	}
}
